<%@ page language="java" import="java.util.*" import="java.sql.*" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ page import="com.example.demo2.DBUtil" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>后台管理系统</title>
</head>
<link rel="stylesheet" href="css/bootstrap.css">
<body>
<style>
    .center{display: flex !important;align-content: center;justify-content: center;align-items: center;}
</style>
<div style="display: flex; justify-content: center;flex-direction: column;align-items: center;">
    <%@include file="admin_header.jsp"%>
    <div style="margin-top: 20px">
        <div style="display: flex;justify-content: space-between;">
            <button type="button" class="btn btn-primary" style="margin-bottom: 20px" data-toggle="modal" data-target="#exampleModal">添加影院</button>
            <a href="ad_xitong.jsp"><button type="button" class="btn btn-success" style="margin-bottom: 20px;">刷新</button></a>
        </div>
         <ul class="list-group list-group-horizontal">
            <li class="list-group-item" style="width: 50px">ID</li>
            <li class="list-group-item"style="width: 150px">影院名称</li>
            <li class="list-group-item"style="width: 150px">品牌</li>
             <li class="list-group-item"style="width: 150px">行政区</li>
             <li class="list-group-item"style="width: 150px">类型</li>
             <li class="list-group-item"style="width: 150px">服务</li>
             <li class="list-group-item"style="width: 150px">距离</li>
             <li class="list-group-item"style="width: 150px">最低金额</li>
             <li class="list-group-item"style="width: 200px">地址</li>
             <li class="list-group-item"style="width: 150px">电话</li>
            <li class="list-group-item"style="width: 250px">操作</li>
        </ul>


        <%
            request.setCharacterEncoding("UTF-8");
            String a_name = request.getParameter("a_name");
            String a_pinp = request.getParameter("a_pinp");
            String a_xzq = request.getParameter("a_xzq");
            String a_leix = request.getParameter("a_leix");
            String a_fuw = request.getParameter("a_fuw");
            String a_jvli = request.getParameter("a_jvli");
            String a_qian = request.getParameter("a_qian");
            String a_dizhi = request.getParameter("a_dizhi");
            String a_phone = request.getParameter("a_phone");

            String u_id = request.getParameter("u_id");
            String u_name = request.getParameter("u_name");
            String u_pinp = request.getParameter("u_pinp");
            String u_xzq = request.getParameter("u_xzq");
            String u_leix = request.getParameter("u_leix");
            String u_fuw = request.getParameter("u_fuw");
            String u_jvli = request.getParameter("u_jvli");
            String u_qian = request.getParameter("u_qian");
            String u_dizhi = request.getParameter("u_dizhi");
            String u_phone = request.getParameter("u_phone");
            String d_id = request.getParameter("d_id");
            Connection cn = null;
            PreparedStatement ps = null;

            ResultSet rs = null;
            String sql = "";
            cn = DBUtil.getConnection();
            sql = "select * from cinema";
            ps = cn.prepareStatement(sql);
            rs = ps.executeQuery();

            String error = "";
//            System.out.println(a_name);
            if (a_name != null && a_pinp !=null){
                int n=0;
                sql = "insert into cinema(name,pinp,xzq,leix,fuw,jvli,qian,dizhi,phone) values(?,?,?,?,?,?,?,?,?)";
                ps = cn.prepareStatement(sql);
                ps.setObject(1, a_name);
                ps.setObject(2, a_pinp);
                ps.setObject(3, a_xzq);
                ps.setObject(4, a_leix);
                ps.setObject(5, a_fuw);
                ps.setObject(6, a_jvli);
                ps.setObject(7, a_qian);
                ps.setObject(8, a_dizhi);
                ps.setObject(9, a_phone);
                n= ps.executeUpdate();
                response.sendRedirect("ad_xitong.jsp");
            }
            if (u_id != null){
                int n=0;
                sql = sql = "UPDATE cinema SET name =\""+u_name+"\", pinp =\""+ u_pinp +"\" "+ ",xzq=\"" + u_xzq + "\",leix=\"" + u_leix +
                        "\",fuw=\""+ u_fuw + "\",jvli=\"" + u_jvli + "\",qian=" + u_qian + ",dizhi=\"" + u_dizhi +
                        "\",phone=\"" + u_phone + "\" WHERE id=" + u_id;
                System.out.println(sql);
                ps = cn.prepareStatement(sql);
                n= ps.executeUpdate();
                response.sendRedirect("ad_xitong.jsp");

            }
//
            if (d_id != null){
              int n=0;
              sql = "DELETE FROM `gp`.`cinema` WHERE `id` = " + d_id;
//              System.out.println(sql);
              ps = cn.prepareStatement(sql);
              n= ps.executeUpdate();
              response.sendRedirect("ad_xitong.jsp");
            }
            while(rs.next()){
                int id = rs.getInt("id");
                String name = rs.getString("name");
                String pinp = rs.getString("pinp");
                String xzq = rs.getString("xzq");
                String leix = rs.getString("leix");
                String fuw = rs.getString("fuw");
                String jvli = rs.getString("jvli");
                String qian = rs.getString("qian");
                String dizhi = rs.getString("dizhi");
                String phone = rs.getString("phone");
        %>
        <ul class="list-group list-group-horizontal-sm">
            <li class="list-group-item center"style="width: 50px;"><%=id%></li>
            <li class="list-group-item center"style="width: 150px"><%=name%></li>
            <li class="list-group-item center"style="width: 150px"><%=pinp%></li>
            <li class="list-group-item center"style="width: 150px"><%=xzq%></li>
            <li class="list-group-item center"style="width: 150px;"><%=leix%></li>
            <li class="list-group-item center"style="width: 150px"><%=fuw%></li>
            <li class="list-group-item center"style="width: 150px"><%=jvli%></li>
            <li class="list-group-item center"style="width: 150px"><%=qian%></li>
            <li class="list-group-item center"style="width: 200px"><%=dizhi%></li>
            <li class="list-group-item center"style="width: 150px"><%=phone%></li>
            <li class="list-group-item center"style="width: 250px">
                <button type="button" class="btn btn-primary btn-sm"
                        data-toggle="modal" data-target="#upxtModal<%=id%>"
                        style="margin-bottom: 20px;margin-right: 5px">修改</button>
                <a href="ad_fyt.jsp?y_id=<%=id%>" type="button" class="btn btn-success btn-sm " style="margin-bottom: 20px;margin-right: 5px">放映厅</a>

                <a href="ad_xitong.jsp?d_id=<%=id%>" type="button" class="btn btn-info btn-sm" style="margin-bottom: 20px">删除</a>
            </li>
        </ul>
        <%@include file="up_xitong.jsp"%>
        <%
            }
        %>
    </div>


    <!-- Modal -->
    <div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered modal-dialog-scrollable">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">添加影院</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>


                <div class="modal-body">
                    <form action="ad_xitong.jsp" method="post">
                        <div class="form-group">
                            <label for="name">影院名称:</label>
                            <input type="text" name="a_name" required class="form-control" id="name">
                        </div>
                        <div class="form-group">
                            <label for="pinp">品牌:</label>
                            <select class="form-control" name="a_pinp" id="pinp">
                                <option>万达影城</option>
                                <option>百老汇影城</option>
                                <option>环球影城</option>
                                <option>万象影城</option>
                            </select>
                        </div>
                        <div class="form-group">
<%--                            <label for="xzq">行政区:</label>--%>
<%--                            <input type="text" name="a_xzq" required class="form-control"--%>
<%--                                   id="xzq">--%>
                            <label for="xzq">行政区:</label>
                            <select class="form-control" name="a_xzq" id="xzq">
                                <option>地铁附近</option>
                                <option>朝阳区</option>
                                <option>海淀区</option>
                                <option>丰台区</option>
                                <option>昌平区</option>
                                <option>通州区</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <label for="leix">类型:</label>
                            <select class="form-control" name="a_leix" id="leix">
                                <option>IMAX厅</option>
                                <option>4K厅</option>
                                <option>4D厅</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <label for="fuw">服务:</label>
                            <select class="form-control" name="a_fuw" id="fuw">
                                <option>改签</option>
                                <option>退票</option>
                                <option>改签/退票</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <label for="jvli">距离:</label>
                            <input type="text" name="a_jvli" required class="form-control" id="jvli">
                        </div>
                        <div class="form-group">
                            <label for="qian">最低金额:</label>
                            <input type="number" name="a_qian" required class="form-control"
                                   id="qian">
                        </div>
                        <div class="form-group">
                            <label for="dizhi">地址:</label>
                            <input type="text" name="a_dizhi" required class="form-control"
                                   id="dizhi">
                        </div>
                        <div class="form-group">
                            <label for="phone">电话:</label>
                            <input type="text" name="a_phone" required class="form-control"
                                   id="phone">
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                            <button type="submit" class="btn btn-primary">确认</button>
                        </div>
                    </form>
                </div>

            </div>
        </div>
    </div>

</div>
<script src="js/jQuery.js"></script>
<script src="js/bootstrap.js"></script>

</body>
</html>